package com.hxd.otc.module.my.activity;

import android.os.Bundle;
import android.view.View;

import com.hxd.otc.common.UserHelper;
import com.hxd.otc.dialog.EditAccountInfoDialog;

/**
 * Created by lzy on 2018/6/15 0015.
 * description ${编辑用户信息}
 */
public class EditAccountActivity extends AccountInfoActivity {

    private String mModify;

    private boolean isNeedCheckPwd = true;
    private EditAccountInfoDialog mEditAccountInfoDialog;

    @Override
    protected void initView() {
        super.initView();
        Bundle bundle = getBundle();
        mModify = bundle.getString(EXTRA_MODIFY_TYPE);
        mViewUid.setVisibility(View.GONE);
        mViewNickName.setVisibility(View.GONE);
        mFlUid.setVisibility(View.GONE);
        if (EditAccountInfoDialog.MODIFY_TYPE_CHECKPWD.equals(mModify)) {
            mTvNickName.setVisibility(View.GONE);
            isNeedCheckPwd = true;
            onModifyName();
        } else {
            mTvName.setVisibility(View.GONE);
            onModifyNickName();
        }

    }

    @Override
    protected void onModifyName() {
        mEditAccountInfoDialog = new EditAccountInfoDialog(this);
        mEditAccountInfoDialog.setModifyType(isNeedCheckPwd ? EditAccountInfoDialog.MODIFY_TYPE_CHECKPWD : EditAccountInfoDialog.MODIFY_TYPE_NAME);
        mEditAccountInfoDialog.setOnConfirmClickListener(new EditAccountInfoDialog.OnConfirmClickListener() {
            @Override
            public void onCheckPasswordSuccess() {
                isNeedCheckPwd = false;
            }

            @Override
            public void onModifyNameSuccess(String newName) {
                UserHelper.updateNickName(newName);
            }

            @Override
            public void onModifyNickNameSuccess(String newNickName) {

            }
        });
        mEditAccountInfoDialog.setDefaultText(UserHelper.getRealName()).show();
    }

    /**
     * 修改昵称
     */
    @Override
    protected void onModifyNickName() {
        new EditAccountInfoDialog(this)
                .setModifyType(EditAccountInfoDialog.MODIFY_TYPE_NICKNAME)
                .setDefaultText(UserHelper.getNickName()).show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mEditAccountInfoDialog != null) {
            mEditAccountInfoDialog.dismiss();
            mEditAccountInfoDialog = null;
        }
    }
}
